package com.itheima.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ProjectController {
    @Value("${spring.application.name}")
    private String appName;
    @Value("${server.port}")
    private String serverPort;
    @GetMapping(value = "/project/{name}")
    @SentinelResource(value = "findProject",
            blockHandler ="findProjectBlockHandler")
    public String findProject(@PathVariable("name") String name)  {

        return "<h2>服务访问成功！</h2>服务名称："+appName+"， 端口号："
                + serverPort +"<br /> 查询的项目：" + name;
    }
    public String findProjectBlockHandler(@PathVariable("name") String name,
        BlockException ex)  {
        System.out.println("排队人数过多！");
        return "排队人数过多！" ;
    }
}